package com.itxiuyixiu.tools.security.user;


import com.itxiuyixiu.tools.util.returns.ReturnVo;
import org.springframework.http.HttpStatus;
import org.springframework.security.authentication.InternalAuthenticationServiceException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author 黄磊
 * @date 2020/1/26
 */
@ControllerAdvice
public class SecurityExceptionHandler {
    /**
     * 拦截捕捉自定义异常 MyException.class
     */
    @ResponseBody
    @ExceptionHandler(value = UserNotFoundException.class)
    public ReturnVo userErrorHandler(UserNotFoundException ex) {
        return new ReturnVo(HttpStatus.UNAUTHORIZED, ex.getMessage());
    }
}
